<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<script>
  let arr = [
    {
      name: 'bike',
      price: 100
    },
    {
      name: 'cake',
      price: 10
    },
    {
      name: 'apple',
      price: 6
    },
    {
      name: 'phone',
      price: 999
    },
  ]

  function order(filed, type = 'asc') {
    return type === 'asc' ? (a, b) => a[filed] - b[filed] : (a, b) => b[filed] - a[filed]
  }

  let sortArr = arr.sort(order('price', 'desc'));
  console.log(sortArr)
</script>
</body>
</html>